let fs = require('fs'), async = require('async')

async.waterfall([
  function readData(callback) {
    fs.readFile('./data/data1.txt', 'utf8', (err, data) => {
      console.log(err, data, 'readData')      
      callback(err,data);
    })
  },
  function modify(text, callback) {
    let adjdata = text.replace(/somecompany\.com/g, 'burningbird.net');
    console.log(adjdata, 'modify')
    callback(null, adjdata);
  },
  function writeData(text, callback) {
    fs.writeFile('./data/data1.txt', text, (err) => {
      console.log('writeData:' , text)
      callback(err, text)
    })
  },
  (result, err) => {
    if(err.message) {
      console.error(err, 'err')
    }
    if(result){
      console.log(result, 'success')
    }
  }
])

